package com.xaicode.ctoroad.netty.nio;

import java.nio.IntBuffer;

/**
 * @author Locker xaicode@sina.com
 */
public class BasicBuffer {

    public static void main(String[] args) {

        // 创建buffer，指定空间
        IntBuffer intBuffer = IntBuffer.allocate(5);

        // 写入数据
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i * 2);
        }

        // 重点：读写切换
        intBuffer.flip();

        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }

    }

}
